{
语法百题 解题报告：
 http://git.oschina.net/et0662/sznoi-grammar/ 
}
var
	map:array[1..5,1..5] of boolean;
	b:array[1..5] of 1..4;
	total: integer=0;

procedure search(i:integer);
var
	j,k:integer;
	flag:boolean;
begin
	if(i=6)then
	begin
		flag:=true;
		for j:=1 to 5 do
		for k:=1 to 5 do
		begin
			if (j<>k) and map[j,k] then
			begin
				if(b[j]=b[k])then
				begin
					flag:=false;
					break;
				end;
			end;
			if not flag then break;
		end;
		
		if flag then inc(total);
	end
	else
	begin
		for k:=1 to 4 do
		begin
			b[i]:=k;
			search(i+1);
		end;
	end;
end;
var
	i,j,k,n:integer;
begin
	readln(n);
	for i:=1 to 5 do
	for j:=1 to 5 do
		map[i,j]:=false;
	for i:=1 to n do
	begin
		readln(j,k);
		map[j,k]:=true;
	end;
	search(1);
	writeln(total);
end.
